﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Zadanie5
{
    public partial class Form1 : Form
    {
        private ReadersWriters problem;

        public Form1()
        {
            InitializeComponent();
        }

        private void UpdateView()
        {
            try
            {
                this.Invoke((MethodInvoker)delegate
                {
                    label1.Text = "Readers: " + problem.Readcount;
                    label2.Text = "Writers: " + problem.WritersActive + ", Waiting: " + problem.WriteCount;
                });
            }
            catch
            {
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            problem = new ReadersWriters();
            problem.Run();
            problem.Changed += UpdateView;
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (problem != null) problem.Stop();
        }
    }
}
